<style>
    .avatar {
        width: 30px;
        height: 30px;
    }
    
    .layui-table-body .layui-table-cell {
        height: 48px;
        line-height: 48px;
    }
</style>
<div class="widget-head" style="margin-top:0;">
    <div class="widget-title">管理员管理</div>
</div>
<div class="layui-container" style="width:100%;">
    <div class="layui-clear">
        <a class="layui-btn fl" onclick="think_open('/user/admins/edit?role=admin','添加管理员',['60%','60%'],0)">添加</a>

        <a class="layui-btn layui-btn-danger think-btn fl" data-type="del" data-url="/api/user/del">批量删除</a>
        <form method="GET" action="/user/admins/index" class="fr layui-form" style="width:400px;">
            <div class="layui-input-inline fl" style="width:100px;">
                <php>$types = ['realname'=>'真实姓名','username'=>'账号','mobile'=>'手机号'];</php>
                <select name="searchtype">
                    <foreach name="types" item="vo" key="k">
                        <option value="{$k}" <if condition="$_GET['searchtype'] eq $k">selected</if>>{$vo}</option>
                    </foreach>
                </select>
            </div>
            <div class="layui-input-inline fr" style="width:300px;">
                <button class="layui-btn fr" lay-submit>搜索</button>
                <input type="text" class="layui-input fr" style="width:230px;" name="keywords" placeholder="请输入关键词" value="{$_GET['keywords']}">
            </div>
            <?php
                $condition = [];
                if($_GET['searchtype'] && $_GET['keywords']){
                    $condition['searchtype'] = $_GET['searchtype'];
                    $condition['keywords'] = $_GET['keywords'];
                }
            ?>
                <script>
                    var condition = eval('({:json_encode($condition,JSON_UNESCAPED_UNICODE)})');
                </script>
        </form>
    </div>
    <table id="list"></table>
    <script type="text/html" id="barDemo">
        <div class="action-btn">
            <a href="javascript:;" class="mini_del" data-url="/user/api/del/ids/{{d.id}}">删除</a>
            <a href="javascript:;" onclick="think_open('/user/admins/edit/id/{{d.id}}','修改账户',['60%','60%'],0)">修改</a>
        </div>
    </script>
    <script type="text/html" id="restatus">
        {{# if(d.status == -1){ }} <span class="xy-status red">禁用</span>{{# } else { }} <span class="xy-status">正常</span> {{# } }}
    </script>
</div>

<script>
    layui.use(['jquery', 'think', 'table'], function() {
        var think = layui.think,
            $ = layui.jquery,
            table = layui.table;
        //第一个实例
        think.render({
                id: 'question-list',
                elem: '#list',
                method: 'post',
                url: '/user/api/getdata_admin',
                where: condition,
                skin: 'line',
                page: true,
                // toolbar: true,
                cols: [
                    [ //表头
                        {
                            type: 'checkbox'
                        }, {
                            field: 'id',
                            title: 'ID',
                            width: 90,
                            sort: true
                        }, {
                            field: 'username',
                            title: '用户名',
                            sort: true
                        }, {
                            title: '头像',
                            width: 60,
                            templet: function(d) {
                                return d.avatar == '' || d.avatar == null ? '<img src="/Public/common/img/boy1.png" class="avatar">' : '<img src="' + d.avatar + '" class="avatar">';
                            }
                        }, {
                            field: 'realname',
                            title: '真实姓名'
                        }, {
                            field: 'mobile',
                            title: '手机号',
                        }, {
                            field: 'role',
                            title: '角色',
                            templet: function(d) {
                                return d.role == 'admin' ? '管理员' : '普通账户';
                            }
                        }, {
                            field: 'status',
                            title: '账户状态',
                            width: 100,
                            toolbar: '#restatus'
                        }, {
                            field: 'create_time',
                            title: '创建时间',
                            width: 170,
                            templet: function(d) {
                                return think_time(d.create_time, 'Y-m-d H:i:s'); //think_time()是think.js里面的方法
                            }
                        }, {
                            title: '操作',
                            width: 110,
                            align: 'center',
                            toolbar: '#barDemo'
                        }
                    ]
                ]
            },
            '{$_GET["searchtype"]}',
            '{$_GET["keywords"]}');
    });
</script>